{% extends "base.html" %}
{% block content %}
{% if statistics %}

<h4>Information for {{days}} days. Total number of tasks: {{statistics.total}}, Average per day: {{statistics.average}}</h4>

{% if statistics.detections %}
  <table class="table table-striped table-bordered">
    {% for block in statistics.detections.items %}
      {% if block.family %}
        <td>{{block.total}}: <a href="/analysis/search/detections:{{block.family}}"><span style="color:#EE1B2F;font-weight: bold;">{{block.family}}</span></a></td>
      {% endif %}
      {% if forloop.counter|divisibleby:"5" %}
          </tr>
      {% elif forloop.last %}
          </tr>
      {% endif %}

    {% endfor %}
</table>
{% endif %}

{% if statistics.asns %}
  <center><h4>Top ASN</h4></center>
  <table class="table table-striped table-hover" style="table-layout: fixed; width: 50%; text-align: center;margin-left: auto;margin-right: auto;">
    {% for block in statistics.asns %}
      {% if block.asn %}
        <td>{{block.total}}: <a href="/analysis/search/asn:{{block.asn}}"><span style="color:#EE1B2F;font-weight: bold;">{{block.asn}}</span></a></td>
      {% endif %}
      {% if forloop.counter|divisibleby:"5" %}
          </tr>
      {% elif forloop.last %}
          </tr>
      {% endif %}

    {% endfor %}
</table>
{% endif %}

<h4>Tasks per day</h4>
<table class="table table-striped table-hover">
    <thead>
      <tr>
        <th scope="col">Day</th>
        <th scope="col">Tasks Added</th>
        <th scope="col">Tasks Reported</th>
        <th scope="col">Tasks Failed</th>
      </tr>
    </thead>
    <tbody>
    {% for day, block in statistics.tasks.items %}
        <tr>
            <th scope="row">{{day}}</th>
            <td>{{block.added}}</td>
            <td>{{block.reported}}</td>
            <td>{{block.failed}}</td>
        </tr>
    {% endfor %}
    </tbody>
  </table>


<hr />

  {% if statistics.custom_statistics %}
  <h4>Custom Signatures data only for Volatility/static extraction</h4>
  <table class="table table-striped table-hover">
    <thead>
      <tr>
        <th scope="col">Name</th>
        <th scope="col">Total time in minutes</th>
        <th scope="col">Runs</th>
        <th scope="col">Extracted </th>
        <th scope="col">Average time in minutes(Total/runs)</th>
      </tr>
    </thead>
    <tbody>
    {% for name, time in statistics.custom_statistics.items %}
        <tr>
            <td>{{name}}</td>
            <td>{{time.total}}</td>
            <td>{{time.runs}}</td>
            <td>{{time.successful}}</td>
            <td>{{time.average}}</td>
        </tr>
    {% endfor %}
    </tbody>
  </table>
{% endif %}
<h4>Time per module</h4>
<div class="container">
    <div class="row">
        {% if statistics.processing %}
        <div class="col-sm">
            <h4>Processing</h4>
            <table class="table table-striped table-hover">
              <thead>
                <tr>
                  <th scope="col">Name</th>
                  <th scope="col">Total time in minutes</th>
                  <th scope="col">Runs</th>
                  <th scope="col">Average time in minutes(Total/runs)</th>
                </tr>
              </thead>
              <tbody>
              {% for name, time in statistics.processing.items %}
                  <tr>
                      <td>{{name}}</td>
                      <td>{{time.total}}</td>
                      <td>{{time.runs}}</td>
                      <td>{{time.average}}</td>
                  </tr>
              {% endfor %}
              </tbody>
            </table>
        </div>
        {% endif %}
        {% if statistics.signatures %}
        <div class="col-sm">
            <h4>Signatures</h4>
            <table class="table table-striped table-hover">
              <thead>
                <tr>
                  <th scope="col">Name</th>
                  <th scope="col">Total time in minutes</th>
                  <th scope="col">Runs</th>
                  <th scope="col">Average time in minutes(Total/runs)</th>
                </tr>
              </thead>
              <tbody>
              {% for name, time in statistics.signatures.items %}
                  <tr>
                      <td>{{name}}</td>
                      <td>{{time.total}}</td>
                      <td>{{time.runs}}</td>
                      <td>{{time.average}}</td>
                  </tr>
              {% endfor %}
              </tbody>
            </table>
        </div>
        {% endif %}
        {% if statistics.reporting %}
        <div class="col-sm">
            <h4>Reporting</h4>
            <table class="table table-striped table-hover">
              <thead>
                <tr>
                  <th scope="col">Name</th>
                  <th scope="col">Total time in minutes</th>
                  <th scope="col">Runs</th>
                  <th scope="col">Average time in minutes(Total/runs)</th>
                </tr>
              </thead>
              <tbody>
              {% for name, time in statistics.reporting.items %}
                  <tr>
                      <td>{{name}}</td>
                      <td>{{time.total}}</td>
                      <td>{{time.runs}}</td>
                      <td>{{time.average}}</td>
                  </tr>
              {% endfor %}
              </tbody>
            </table>
        </div>
        {% endif %}
    </div>
</div>

{% else %}
    <div class="alert alert-primary">No statistics found.</div>
{% endif %}

{% if statistics.distributed_tasks %}
<h4>Cluster details</h4>
<div class="container">
    <div class="row">
        {% for day, block in statistics.distributed_tasks.items %}
        <div class="col-2">
            <th scope="row">{{day}}</th>
            <td>
            {% for name, tasks in block.items %}
              <li>Node: {{name}} - Tasks {{tasks}}</li>
            {% endfor %}
          </td>

        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

{% endblock %}
